// mobile bind
// ============

define(['zepto', 'sui', 'dropload'], function($){
  return {
    init: function(data) {
      if(location.href.indexOf("#reloaded")==-1){
        location.href=location.href+"#reloaded";
        location.reload();
      }
      this.initScroll();
    },
    
    initScroll: function() {
        var page = 1;
        var size = 6;
        $('.list-content').dropload({
        	scrollArea : $(".profile-bill-content"),
            autoLoad: false,
            loadDownFn : function(me){
                page++;
                var result = '';
                $.ajax({
                    type: 'GET',
                    url: window.location.pathname + '/orders?page='+page+'&everyPage='+size,
                    dataType: 'json',
                    success: function(data){
                        data = data.data.orders
                        var arrLen = data ? data.length : 0;
                        if(arrLen > 0){
                            for(var i=0; i<arrLen; i++){
                                result += '<div class="item-content">'
			              		          + '<div class="item-inner">'
			        			          + '<div class="col-50 detail">'
			        			            + '<p class="no-margin">订单号： ' + data[i].code + '</p>'
			        			            + '<p class="no-margin">下单时间： ' + data[i].create_time + '</p>'
			        			            + '<p class="no-margin">订单金额： ' + Math.ceil(data[i].cny_pay_price + data[i].distribution_reward_record.amount/100) + '.00元</p>'
			        			          + '</div>'
			        			          + '<div class="col-50 royalty">'
			        			            + '<i class="iconfont ' + (data[i].distribution_reward_record.status === 'UNCONSUMED' ? 'iconfont-lock' : ' ') + '"></i>'
			        			            + '<div class="price" style="display: inline-block;vertical-align: middle;text-align: center; margin-left: .25rem;">'+ data[i].distribution_reward_record.amount/100 + ''
			        			              + '<br><span style="font-size: .6rem;">提成</span>'
			        			            + '</div>'
			        			          + '</div>'
			        			        + '</div>'
			        		        + '</div>'
                            }
                        // 如果没有数据
                        }else{
                            // 锁定
                            me.lock();
                            // 无数据
                            me.noData();
                        }
                        setTimeout(function(){
                            $('.list-container').append(result);
                            // 每次数据插入，必须重置
                            me.resetload();
                        },1000);
                    },
                    error: function(xhr, type){
                        alert('Ajax error!');
                        me.resetload();
                    }
                });
            }
        });
    }
  }
})